package com.tnl.app.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.tnl.app.entity.Evaluate;
import com.tnl.app.entity.Safedsales;
import com.tnl.base.BaseDAO;
import com.tnl.utils.DateUtil;


@Repository
public class SafedsalesDAO {
	private static final String SQL_GET_ID = "select * from tb_safesales  where id = ?";
	private static final String SQL_GET_HUNTER_EVALUATE = "select * from tb_safesales  where hunterId = ?";
	private static final String SQL_GET_ORDERID = "select * from tb_safesales  where orderId=?";
	private static final String SQL_GET_BUYEREVA = "select * from tb_safesales  where buyerId=? order by id desc";
	private static final String SQL_GET_TYPE_CONTENT = "SELECT * from tb_safesales where 1=1 limit ?,?";
	private static final String SQL_GET_ALL = "select * from tb_safesales ";
	private static final String SQL_SAVE = "INSERT INTO tb_safesales (orderId, buyerId, buyerName, orderdescIds, afterReason, afterRequest, afterContent, afterMoney, afterUpdateTime, afterCreateTime, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
	
	public List<Safedsales> getALL() {

		return BaseDAO.queryForList(Safedsales.class, SQL_GET_ALL);

	}
	
	public Safedsales getById(int Id) {
		return  BaseDAO.queryForObject(Safedsales.class, SQL_GET_ID, Id);
	}
	
	public Safedsales getByOrderId(Long Id) {
		return  BaseDAO.queryForObject(Safedsales.class, SQL_GET_ORDERID, Id);
	}
	
	public List<Safedsales> getByContent(int offset,Integer pageSize){
		return  BaseDAO.queryForList(Safedsales.class, SQL_GET_TYPE_CONTENT,offset,pageSize);
	}
	
	public List<Safedsales> getHunterByEva(Integer hunterid){
		return BaseDAO.queryForList(Safedsales.class, SQL_GET_HUNTER_EVALUATE, hunterid);
	}
	public int save(Safedsales safed) {
		if (safed == null) {
			return -1;
		}
		Long id = BaseDAO.save(SQL_SAVE, safed.getOrderId(), safed.getBuyerId(),
				safed.getBuyerName(), safed.getOrderdescIds(), safed.getAfterReason(),
				safed.getAfterRequest(), safed.getAfterContent(), safed.getAfterMoney(),
				safed.getAfterUpdateTime(), safed.getAfterCreateTime(), safed.getStatus());
		if (id != null) {
			return id.intValue();
		}
		return -1;
	}
	
	public List<Safedsales> getBuyerSafedId(String openid){
		return BaseDAO.queryForList(Safedsales.class, SQL_GET_BUYEREVA, openid);
	}
	
	
}
